package com.oss.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

import org.springframework.beans.propertyeditors.CustomBooleanEditor;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.support.WebBindingInitializer;
import org.springframework.web.context.request.WebRequest;

/**
 * @author xueqiang.mi
 * @date 2010-2-1
 */
public class DefaultBindingInitializer implements WebBindingInitializer {

	@Override
	public void initBinder(WebDataBinder binder, WebRequest request) {
		binder.registerCustomEditor(String.class,
				new StringTrimmerEditor(false));
		binder.registerCustomEditor(Boolean.class, new CustomBooleanEditor(
				false));
		binder.registerCustomEditor(Long.class, new CustomNumberEditor(
				Long.class, true));

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		TimeZone zone = TimeZone.getTimeZone("Asia/Shanghai");
		sdf.setTimeZone(zone);
		sdf.setLenient(true);
		binder
				.registerCustomEditor(Date.class, new CustomDateEditor(sdf,
						true));
	}
}
